package cn.kgc.novel.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

public class SmsUtils {

    public static void sendSms(String phone,String code){
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5t8N1mjbG9TXmEX6h7qU",
                "N5GuzoiaISOBem9JUlk8fyOuXJDiNH");

        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();
        request.setSysRegionId("cn-hangzhou");
        request.setPhoneNumbers(phone);
        request.setSignName("许士玮的博客");
        request.setTemplateCode("SMS_463662310");
        request.setTemplateParam("{\"code\":\""+code+"\"}");
        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(response);
            System.out.println(response.getCode());
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }


}
